//
//  NotiDetailVC.swift
//  SBSafetyApp
//
//  Created by Lina on 2022/12/5.
//
// 【首页-通知】通知详情

import Foundation
import UIKit

class NotiDetailVC: SubLevelViewController {
    let detailV = NotiDetailView()

    var id: Int64!
            
    init(id: Int64!) {
        super.init(nibName: nil, bundle: nil)
        self.id = id
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        title = "通知详情"
        view.backgroundColor = .white
        
        setupUI()
        
        reloadData()
    }
    
    func reloadData() {
        API.getNoticeDetail(withId: id) { responseModel in
            DispatchQueue.main.async {
                let type = MsgItemType(rawValue: responseModel.model?.noticeType ?? "1")
                switch type {
                case .notify: self.title = "通知详情"; break
                case .notion: self.title = "公告详情"; break
                case .setting: self.title = "系统消息详情"; break
                default: break
                }
                self.detailV.reloadData(withModal: responseModel.model)
            }
        }
    }
    
    // MARK: - Setup
    
    func setupUI() {
        view.addSubview(detailV)
        detailV.snp.makeConstraints { (make) in
            make.left.right.equalToSuperview()
            make.top.equalTo(view.safeAreaLayoutGuide.snp.top)
            make.bottom.equalTo(view.safeAreaLayoutGuide.snp.bottom)
        }
    }
    
}
